# myscript.py

import cx_Oracle

# Connect as user "hr" with password "welcome" to the "orclpdb1" service running on this computer.
# 配置连接
db = cx_Oracle.connect("system", "123456", "localhost/orcl")

# 创建游标
cursor = db.cursor()

'''
创建表

sql = "create table books(id int,name varchar2(10),gender varchar(4) default '男' check(gender in ('男','女')))"
# 执行单条语句
cursor.execute(sql)
db.commit()
# 执行多条语句
# cursor.executemany()
'''

'''
增加数据

sql = "insert into books values(6,'坏坏','女')"
cursor.execute(sql)
db.commit()
'''


'''
修改数据

sql = "update books set gender='男' where name='杜甫'"
cursor.execute(sql)
db.commit()
'''



'''
删除数据

sql = "delete from books where name='李白'"
cursor.execute(sql)
db.commit()
'''



'''
查询数据

sql = "select * from books"
cursor.execute(sql)
db.commit()
a = cursor.fetchone()
b = cursor.fetchall()
print(a,b)
'''





'''
需要外部参数 

# 方法1
sql = "select * from books a where a.id=:id"
cursor.prepare(sql)
cursor.execute(None,{'id':5})
a = cursor.fetchall()
print(a)

# 方法二
sql = "select * from books a where a.id= %s"
cursor.execute(sql%5)
a = cursor.fetchall()
print(a)


cursor.close()
db.close()
'''